﻿// <copyright file="Closure.cs" company="Joe Chung">
// Copyright © 2008 by Joe Chung.
// </copyright>
namespace NScheme
{
    using System;

    public class Closure : NScheme.Procedure
    {
        public object parms;

        public object body;

        public Environment env;

        public Closure(object parms, object body, Environment env)
        {
            this.parms = parms;
            this.env = env;
            this.body = body is Pair & rest(body) == null ? first(body) : cons("begin", body);
        }

        public override object apply(Scheme interpreter, object args)
        {
            return interpreter.eval(body, new Environment(parms, args, env));
        }
    }
}